define(['jquery', 'bootstrap', 'backend', 'table', 'form','echarts', 'echarts-theme'], function ($, undefined, Backend, Table, Form,Echarts) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'game/index' + location.search,
                    add_url: 'game/add',
                 //   edit_url: 'game/edit',
                 //   del_url: 'game/del',
                    multi_url: 'game/multi',
                    import_url: 'game/import',
                    table: 'game',
                }
            });
            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                searchFormTemplate: 'customformtpl',
                columns: [
                    [
                    //    {checkbox: true},
                       // {field: 'id', title: __('Id')},
                        {field: 'mon', title: __('月份'), operate: 'LIKE'},
                        {field: 'game_name', title: __('游戏'), operate: 'LIKE'},
                        {field: 'num', title: __('参与总次数')},
                        {field: 'user_num', title: __('参与总人数')},
                        {field: 'coin', title: __('获取总金币数')},

                      //  {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [{
                                name: 'checkout',
                                text: __('查看'),
                                icon: 'fa fa-list',
                                classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                url:function (row) {
                                    return "game/date?month="+row.mon+"&game_id="+row.game_id;
                                },

                                refresh: true,
                            } ],
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        date: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'game/date' + location.search,
                 //   add_url: 'game/add',
                 //   edit_url: 'game/edit',
                 //   del_url: 'game/del',
                    multi_url: 'game/multi',
                    import_url: 'game/import',
                    table: 'game',
                }
            });
            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                searchFormTemplate: 'customformtpl',
                columns: [
                    [
                        //    {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        {field: 'mon', title: __('日期'), operate: 'LIKE'},
                        {field: 'game_name', title: __('游戏'), operate: 'LIKE'},
                        {field: 'num', title: __('参与总次数')},
                        {field: 'user_num', title: __('参与总人数')},
                        {field: 'coin', title: __('获取总金币数')},
                        //  {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [{
                                name: 'hot',
                                text: __('查看'),
                                icon: 'fa fa-list',
                                classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                url:function (row) {
                                    return "game/hot?date="+row.mon+"&game_id="+row.game_id;
                                },

                                refresh: true,
                            } ],
                        }
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        hot:function(){

            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'game/hot' + location.search,
                    //   add_url: 'game/add',
                    //   edit_url: 'game/edit',
                    //   del_url: 'game/del',
                    multi_url: 'game/multi',
                    import_url: 'game/import',
                    table: 'game',
                }
            });
            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                searchFormTemplate: 'customformtpl',
                columns: [
                    [
                        //    {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        {field: 'mon', title: __('时间'), operate: 'LIKE'},
                        {field: 'game_name', title: __('游戏'), operate: 'LIKE'},
                        {field: 'num', title: __('参与总次数')},
                        {field: 'user_num', title: __('参与总人数')},
                        {field: 'coin', title: __('获取总金币数')},
                        //  {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}

                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);

            var barChart = Echarts.init(document.getElementById('simplebar-chart'));
            option = {
                xAxis: {
                    type: 'category',
                    axisLine: {
                        lineStyle: {
                            color: "#fff"
                        }
                    },
                    data: Config.b,//['周一', '周二', '周三', '周四', '周五', '周六', '周日','周一', '周二', '周三', '周四', '周五', '周六', '周日','周一', '周二', '周三', '周四', '周五', '周六', '周日','周一', '周二', '周三', '周四', '周五', '周六', '周日','周一', '周二', '周三', '周四', '周五', '周六', '周日']
                },
                yAxis: {
                    type: 'value',
                    axisLine: {
                        lineStyle: {
                            color: "#fff"
                        }
                    }
                },
                series: [{
                    data: Config.a,// [120, 200, 150, 80, 70, 110, 130,120, 200, 150, 80, 70, 110, 130,120, 200, 150, 80, 70, 110, 130,120, 200, 150, 80, 70, 110, 130,120, 200, 150, 80, 70, 110, 500],
                    type: 'bar',
                    itemStyle: {
                        color: "#fff",
                        opacity: 0.6
                    }
                }]
            };
            // 使用刚指定的配置项和数据显示图表。
            barChart.setOption(option);
            Controller.api.bindevent();
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
